package com.sky.controller.employee;

import com.sky.constant.MessageConstant;
import com.sky.dto.RefundPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.RefundService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.Builder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/employee/refund")
@Slf4j
@CrossOrigin
@Builder
@Api(tags = "用户订单退款")
public class RefundController {
    @Autowired
    private RefundService refundService;

    // 会议室状态查看
    @ApiOperation(value="查询所有需退款订单")
    @GetMapping("/page")
    public Result<PageResult> page(RefundPageQueryDTO refundPageQueryDTO){
        log.info("分页查询: {}", refundPageQueryDTO); //框架会自动将数据封装到实体类对象中，即使有一些为空
        PageResult pageResult = refundService.pageQuery(refundPageQueryDTO);
        return Result.success(pageResult);
    }

    // 同意订单退款
    @PostMapping("/acceptRefund/{orderId}")
    @ApiOperation("同意订单退款")
    public Result<String> accept(@PathVariable Long orderId) {
        log.info("同意订单退款");
        boolean answer = refundService.accept(orderId);
        if (answer) {
            return Result.success(MessageConstant.REFUND_SUCCESS);
        } else {
            return Result.error(MessageConstant.REFUND_FAIL);
        }
    }

    // 拒绝订单退款
    @PostMapping("/refuseRefund/{orderId}")
    @ApiOperation("拒绝订单退款")
    public Result<String> refuse(@PathVariable Long orderId) {
        log.info("拒绝订单退款");
        refundService.refuse(orderId);
        return Result.success();
    }

}
